import SlashAppContext from "@/context/SlashAppContext";
// eslint-disable-next-line
export type Param3DEngineInstance = any

// eslint-disable-next-line
export type GisAppInstance = any

// eslint-disable-next-line
export type GetParam3DInstance = any

declare let window: Window & {
  Param3DEngine: Param3DEngineInstance
  Cesium: any
  engineLoader: {
    loadEngine: () => Promise<void>
  }
  enginePlugin: {
    GisAppFromParam3DEngine: () => Promise<void>
    [x:string]:any
  }
}


/** 获取 Param3DEngine */
export const getParam3DEngine = () => window.Param3DEngine
/** 获取 Param3DEngine */
export const getCesium = () => window.Cesium
export const getEnginePlugin = () => window.enginePlugin

const getParam3dParametersAxios = () => ({
  baseUrl: SlashAppContext.getBaseUrl(),
  sotokenCB: () => ''
})

let isInit = false
/** 是否已经初始化过 */
export const isInited = () => !!isInit

/** 初始化param3d引擎 */
export const initParam3d = async (): Promise<void> => {
  if (window.Param3DEngine) return
  window.engineLoader && (await window.engineLoader.loadEngine())
  isInit = true
}
/**获取初始化Gis的参数 */
export const getInitGisAppConfig = (container: any) => {
  const initGisAppConfig: any = {
    toolbar: false,
    container: container,
    axios: getParam3dParametersAxios(),
    useTerrian: false,
  }
  return initGisAppConfig
}
